package cn.middle.remote.message;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import cn.middle.remote.util.ConversionUtil;

public class LoginSignal extends BaseSignal{

	public LoginSignal() {
		super(SignalHelper.LOGIN);
	}
	
	private String username;
	private String password;
	private Integer clientId;
	
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Integer getClientId() {
		return clientId;
	}
	public void setClientId(Integer clientId) {
		this.clientId = clientId;
	}
	@Override
	public byte[] toData() {
		ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
		DataOutputStream out = new DataOutputStream(bos);
		try {
			out.write(ConversionUtil.writeStringBytes(getUsername()));
			out.write(ConversionUtil.writeStringBytes(getPassword()));
			out.writeInt(getClientId());
			out.flush();
			return bos.toByteArray();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new byte[0];
	}

}
